package com.hyg.lib_common.ui.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hyg.lib_common.DataModel.testting.TesttingAnswer;
import com.hyg.lib_common.DataModel.testting.TesttingXinliQuestion;
import com.hyg.lib_common.R;

import java.util.ArrayList;

/**
 * @author: Administrator
 * @date: 2021/3/22
 */
public class RadioButtonTizhiAdapter extends RecyclerView.Adapter<RadioButtonTizhiAdapter.ViewHolder> {
    ArrayList<TesttingXinliQuestion> list;
    Context context;

    public RadioButtonTizhiAdapter(ArrayList<TesttingXinliQuestion> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_qustions_tizhi_rcv, parent, false);
        RadioButtonTizhiAdapter.ViewHolder holder = new RadioButtonTizhiAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.indexTV.setText((position+1)+"");
        holder.titleTv.setText(list.get(position).getQuestion());
        GridLayoutManager layoutManager = new GridLayoutManager(context, 1);
        RadioButtonAnswerAdapter adapter = new RadioButtonAnswerAdapter(context, list.get(position).getArrayList(),null);
        holder.answerRcv.setLayoutManager(layoutManager);
        holder.answerRcv.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView indexTV, titleTv;
        RecyclerView answerRcv;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            indexTV=itemView.findViewById(R.id.tv_index);
            titleTv=itemView.findViewById(R.id.tv_question_title);
            answerRcv=itemView.findViewById(R.id.rcv_choose_answer);
        }
    }

}
